const XLSX = require('xlsx');
const fs = require('fs');

try {
  // 读取 Excel 文件
  const workbook = XLSX.readFile('student.xlsx');
  
  // 获取第一个工作表
  const sheetName = workbook.SheetNames[0];
  const sheet = workbook.Sheets[sheetName];
  
  // 将工作表转换为 JSON
  const students = XLSX.utils.sheet_to_json(sheet);
  
  // 输出为 JSON 文件
  fs.writeFileSync('students.json', JSON.stringify(students, null, 2));
  
  console.log('Successfully parsed Excel to JSON');
  console.log(`Total students: ${students.length}`);
  console.log('First student:', students[0]);
} catch (error) {
  console.error('Error parsing Excel:', error);
}